import { getEtag } from './qetag';

export function GetFileType(name: string) {
  const list = name.split('.');
  return list[list.length - 1];
}

export function GetMd5(file: Express.Multer.File) {
  return new Promise((resolve) => {
    getEtag(file.buffer, (m: any) => {
      resolve(m);
    });
  });
}

export async function GetUploadFileName(file: Express.Multer.File) {
  const md5 = await GetMd5(file);
  const type = GetFileType(file.originalname);
  return [md5 + '.' + type, type];
}
